package com.fantastic.service.zjs.impl;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.exception.sql.InsertException;
import com.fantastic.common.exception.sql.SelectException;
import com.fantastic.common.exception.sql.UpdateException;
import com.fantastic.common.utils.IsEmptyUtils;
import com.fantastic.mapper.zjs.AccountMemberMapper;
import com.fantastic.model.pojo.zjs.AccountMember;
import com.fantastic.service.zjs.AccountMemberService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/4 20:27
 * @description: 账号和会员卡关联信息service接口实现类
 */
@Service
public class AccountMemberServiceImpl implements AccountMemberService {

    @Resource
    private AccountMemberMapper accountMemberMapper;

    /**
     * 查询账号和会员卡关联信息
     *
     * @param accountMember
     * @return
     */
    @Override
    public List<AccountMember> listAccountMember(AccountMember accountMember) {
        List<AccountMember> accountMembers = accountMemberMapper.listAccountMember(accountMember);
        IsEmptyUtils.listIsEmpty(new SelectException(RespStatusInfo.SELECT_NULL), accountMembers);
        return accountMembers;
    }

    /**
     * 查询单个账号和会员卡关联信息
     *
     * @param accountId
     * @param memberId
     * @return
     */
    @Override
    public AccountMember getAccountMember(Integer accountId, Integer memberId) {
        IsEmptyUtils.integerIsEmpty(new SelectException(RespStatusInfo.DATA_ERROR), accountId, memberId);
        return accountMemberMapper.getAccountMember(accountId, memberId);
    }

    /**
     * 添加账号和会员卡关联信息
     *
     * @param accountMember
     * @return
     */
    @Override
    public Integer insertAccountMember(AccountMember accountMember) {
        IsEmptyUtils.integerIsEmpty(new InsertException(RespStatusInfo.DATA_ERROR),
                accountMember.getAccountId(), accountMember.getMemberId());
        IsEmptyUtils.objectIsNull(new InsertException(RespStatusInfo.DATA_ERROR),
                accountMember.getEndTime(), accountMember.getStartTime());
        return accountMemberMapper.insertAccountMember(accountMember);
    }

    /**
     * 修改账号和会员卡关联信息
     *
     * @param accountMember
     * @return
     */
    @Override
    public Integer updateAccountMember(AccountMember accountMember) {
        IsEmptyUtils.integerIsEmpty(new UpdateException(RespStatusInfo.DATA_ERROR)
                , accountMember.getMemberId(), accountMember.getAccountId());
        return accountMemberMapper.updateAccountMember(accountMember);
    }

    /**
     * 删除账号和会员卡关联信息
     *
     * @param accountId
     * @param memberId
     * @return
     */
    @Override
    public Integer deleteAccountMember(Integer accountId, Integer memberId) {
        IsEmptyUtils.integerIsEmpty(new UpdateException(RespStatusInfo.DATA_ERROR)
                , accountId, memberId);
        return accountMemberMapper.deleteAccountMember(accountId, memberId);
    }

}
